﻿/// <reference path="jquery-1.4.1.min.js" />

var checkname = false;
var checkphone = false;
//用于注册用户的保存请求的异步限制
var checknameandphone = false;

//获取对象
function $$(objId) {
    return document.getElementById(objId);
}

//step1:检测用户名
function CheckUserName(KeyName, flag) 
{
    var value = $("#" + KeyName).val().toString().toLowerCase();
    $("#" + KeyName).val(value);
    if (value == "") 
    {
        ShowError(KeyName, true, "用户名不能为空");
        checkname = false;
    } 
    else 
    {
        if (LenObject(value) < 4) 
        {
            ShowError(KeyName, true, "用户名太短");
            checkname = false;
            return false;
        }
        if (LenObject(value) > 20) 
        {
            ShowError(KeyName, true, "用户名太长");
            checkname = false;
            return false;
        }

        if ((/>|<|\+|,|\[|\]|\{|\}|\/|=|\||\'|\\|\_|\"|:|;|\~|\!|\@|\#|\*|\$|\%|\^|\&|\(|\)|`/i).test(value)) 
        {
            ShowError(KeyName, true, "您填写的用户名中含有了规定外的字符或空格");
            checkname = false;
            return false;
        }
        var t1 = 0;
        for (var i = 0; i < value.length; i++) 
        {
            var a = value.charCodeAt(i);
            if (!(a >= 48 && a <= 57)) { t1 = 1; }
        }
        if (t1 == 0) 
        {
            ShowError(KeyName, true, "不能全为数字");
            checkname = false;
            return false;
        }
        if (isChina(value)) 
        {
            ShowError(KeyName, true, "用户名不能包含汉字");
            checkname = false;
            return false;
        }
        if (flag) 
        {
            CheckNameByAjax(KeyName);
        }
    }
    return checkname;
}
//Ajax检测用户名是否存在
function CheckNameByAjax(KeyName) 
{
    ShowError(KeyName, true, "正在检索。。。");
    var username = $("#"+KeyName).val();
    url = '/AjaxPage/RegisterHelper.aspx?action=checkname&username=' + username + '&run=' + Math.random();
    $.ajax(
    {
        url: url,
        async: true,
        success: function PareseResult(data) 
        {
            var result = data;
            if (result == "恭喜，用户名还没有被注册！") 
            {
                checkname = true;
                $('#DivCommend').css("display", "none");
                ShowRight("txtUserName", true);
                return true;
            }
            else 
            {
                checkname = false;
                ShowError("txtUserName", true, "用户名已被注册");
                var name = $('#txtUserName').val();
                if (name.length > 8) 
                {
                    name = name.substring(0, 8);
                }
                var name1, name2, name3;
                name1 = name + 'agent' + (Math.round(Math.random() * 100));
                name2 = name + 'jjr' + (Math.round(Math.random() * 100));
                name3 = name + (Math.round(Math.random() * 100));
                $('#DivCommend').html('<li>您也可以使用我们为您推荐的用户名：</li><li><label><input type="radio" name="uname" id="name1" value="' + name1 + '" class="noborder" align="absmiddle" onclick=ChooseName("name1","' + KeyName + '") /></label>' + name1 + '</li><li><label><input type="radio" id="name2" name="uname" value="' + name2 + '" class="noborder" align="absmiddle" onclick=ChooseName("name2","' + KeyName + '") /></label>' + name2 + '</li><li><label><input type="radio" id="name3" name="uname" value="' + name3 + '" class="noborder" align="absmiddle" onclick=ChooseName("name3","' + KeyName + '"); /></label>' + name3 + '</li>');
                $('#DivCommend').css("display", "");
            }
        },
        error: AjaxError
    });
}
//选择系统推荐用户名时执行
function ChooseName(id, KeyName) 
{
    $("#" + KeyName).val($("#" + id).val());
    CheckNameByAjax(KeyName);
}

//step2:检测密码
function CheckPwd(KeyName, UserName) {
    var value = $("#" + KeyName).val();
    var username = $("#" + UserName).val();
    if (!value || value == "") 
    {
        ShowError(KeyName, true, "密码不能为空");
        return false;
    }
    if (value.length < 6) 
    {
        ShowError(KeyName, true, "密码长度太短");
        return false;
    }
    if (value.length > 16) 
    {
        ShowError(KeyName, true, "密码长度太长");
        return false;
    }
    if ((/>|<|\+|,|\[|\]|\{|\}|\/|=|\||\'|\\|\"|:|;|\~|\!|\@|\#|\*|\$|\%|\^|\&|\(|\)|`/i).test(value)) 
    {
        ShowError(KeyName, true, "请勿使用特殊字符");
        return false;
    }
    if (value == username) {
        ShowError(KeyName, true, "密码不能与用户名相同");
        return false;
    }
    if ('01234567890'.indexOf(value) != -1 || 'abcdefghijklmnopqrstuvwxyz'.indexOf(value) != -1 || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(value) != -1) 
    {
        ShowError(KeyName, true, "不能使用连续的数字或字符");
        return false;
    }
    for (var i = 0; i < value.length; i++) 
    {
        if (value.charAt(0) != value.charAt(i))
            break;
    }
    if (i == value.length) {
        ShowError(KeyName, true, "不能使用相同的字符");
        return false;
    }
    if (value == '123123' || value == 'abcabc' || value == '123456' || value == '654321') 
    {
        ShowError(KeyName, true, "您输入的密码太过简单");
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckPwdAgain(KeyName, LastKeyName) 
{
    var value = $("#" + KeyName).val();
    var truevalue = $("#" + LastKeyName).val();
    if (value == "" || value == null) 
    {
        ShowError(KeyName, true, "确认密码不能为空");
        return false;
    }
    if (value == truevalue) 
    {
        ShowRight(KeyName, true);
        return true;
    } 
    else 
    {
        ShowError(KeyName, true, "两次密码不一致");
        return false;
    }
}

//step3:填充城市区县商圈
//填充城市
function FillCity(KeyName) 
{
    url = '/AjaxPage/RegisterHelper.aspx?action=getcitys&control=' + KeyName + '&run=' + Math.random();
    $.ajax(
    {
        url: url,
        async: true,
        success: function ProcessCitys(data) {
            if (data) {
                alert(data); data = { r: '北京,唐山,深圳,广州,' };
                //var objResult = { r: '北京,唐山,深圳,广州,' };
                var objResult = data;
                var result = new Array();
                for (var obj in objResult) {
                    result = objResult[obj].split(',');
                }
                var select = document.getElementById(KeyName);
                select.options.add(new Option("请选择", "请选择"));
                for (i = 0; i < result.length; i++) {
                    if (result[i] != "")
                        select.options.add(new Option(result[i], result[i]));
                }
            }
        },
        error: AjaxError
    });
}
//填充区县
function FillDistrict(KeyName, City) 
{
    var sel = document.getElementById(KeyName);
    sel.options.length = 0;
    sel.options.add(new Option("请选择", "请选择"));
    var ready = false;
    for (var i in P) 
    {
        if (ready == true) break;
        for (var j in C[i]) 
        {
            if (C[i][j] == City) 
            {
                for (var k in D[i][j]) 
                {
                    if (D[i][j][k] != "不限")
                        sel.options.add(new Option(D[i][j][k], D[i][j][k]));
                }
                ready = true;
                break;
            }
        }
    }
}
//填充商圈
function FillComareas(KeyName, City, District) 
{
    var sel = document.getElementById(KeyName);
    sel.options.length = 0;
    sel.options.add(new Option("请选择", "请选择"));
    var ready = false;
    for (var i in P) {
        if (ready == true) break;
        for (var j in C[i]) 
        {
            if (C[i][j] == City) 
            {
                for (var k in D[i][j]) 
                {
                    if (D[i][j][k] == District) 
                    {
                        for (var x in A[i][j][k]) 
                        {
                            if (A[i][j][k][x] != "不限")
                                sel.options.add(new Option(A[i][j][k][x], A[i][j][k][x]));
                        }
                        ready = true;
                        break;
                    }
                }
                ready = true;
                break;
            }
        }
    }
}

//填充公司门店
function FillCompany(keyName, city) 
{
    var logoCityList = '北京,上海,广州,深圳,天津,南京,杭州,苏州,成都,武汉,重庆';
    if (city == "") {
        ShowError(keyName, true, "正在检索。。。");
    }
    else 
    {
        if (city != "请选择" && logoCityList.indexOf(city) < 0) {
            $("#selCompany").css("display", "none");
            var txtCompany = $("#selCompany");
            txtCompany.val("");
            txtCompany.css("display", "");
            txtCompany.addClass("width200");
        }
        else 
        {
            $("#selCompany").css("display", "");
            $("#selCompany").addClass("");
        }

        url = '/AjaxPage/RegisterHelper.aspx?action=getcompanies&control=' + keyName + '&city=' + escape(city);
        $.ajax(
        {
            url: url,
            async: true,
            success: function ProcessCompany(data) {
                eval(data);
            },
            error: AjaxError
        });
    }
}
function DoResultMethod2(KeyName, objResult, objResult2) {
    if (objResult) {
        var result = new Array();
        var result2 = new Array();
        for (var obj in objResult) {
            result = objResult[obj].split(',');
        }
        for (var obj in objResult2) {
            result2 = objResult2[obj].split(',');
        }
        var select = $$(KeyName);
        select.options.add(new Option("请选择", "请选择"));
        for (i = 0; i < result.length; i++) {
            if (result[i] != "")
                select.options.add(new Option(result[i], result2[i]));
        }
        select.options.add(new Option("其他", "其他"));
    }
}
function CheckSelect(KeyName, i) {
    var outString = "请选择所在城市";
    if (i == 3)
        outString = "请选择所在县区";
    if (i == 4)
        outString = "请选择商圈";
    var select = $$(KeyName).value;
    if (select == "请选择") {
        ShowDiv(i);
        ShowError(KeyName, true, outString);
        return false;
    }
    else {
        if (i == 2)
            CheckSelect("txtDistrict", 3);
        else if (i == 3)
            CheckSelect("selComareas", 4);
        else {
            ShowRight(KeyName, true);
            return true;
        }
    }
}
function CheckSelect1(KeyName, i) {
    var outString = "请选择所在城市";
    if (i == 3)
        outString = "请选择所在县区";
    if (i == 4)
        outString = "请选择商圈";
    var select = $$(KeyName).value;
    if (select == "请选择") {
        ShowDiv(i);
        ShowError(KeyName, true, outString);
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckMendian(KeyName) {
    var value = $$(KeyName).value;
    if (value == "") {
        ShowTip(KeyName, true);
        return true;
    }
    if (value.length > 20) {
        ShowError(KeyName, true, "输入太长");
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckCompany(KeyName) {
    var value = $$(KeyName).value;
    if (value == "") {
        ShowError(KeyName, true, "所属公司不能为空");
        return false;
    }
    if (LenObject(value) > 12) {
        ShowError(KeyName, true, "输入太长");
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckEmail(KeyName) {
    var value = $$(KeyName).value;
    if (value == "") {
        ShowError(KeyName, true, "安全邮箱不能为空");
        return false;
    }
    if (value.length > 40) {
        ShowError(KeyName, true, "输入太长");
        return false;
    }
    var regEmail = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(value);
    if (!regEmail) {
        ShowError(KeyName, true, "邮箱格式不正确");
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckName(KeyName) {
    if (oo(KeyName).readOnly == true) {
        ShowTip(KeyName, true);
        return true;
    }
    var agentname = trim(oo(KeyName).value);
    if (agentname == '') {
        ShowError(KeyName, true, "真实姓名不能为空");
        return false;
    }
    if (LenObject(agentname) > 10) {
        ShowError(KeyName, true, "您填写的姓名过长");
        return false;
    }
    for (var i = 0; i < agentname.length; i++) {
        var c = agentname.charCodeAt(i);
        if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) {
            ShowError(KeyName, true, "真实姓名必须为中文");
            return false;
        }
    }
    if (havespecial(agentname)) {
        ShowError(KeyName, true, "您填写的姓名中含有了规定外的字符或空格");
        return false;
    }
    ShowRight(KeyName, true);
    return true;
}
function CheckIDCard(KeyName) {
    if (oo(KeyName).readOnly == true) {
        ShowTip(KeyName, true);
        return true;
    }
    var idCard = trim(oo(KeyName).value);
    if (idCard == '') {
        ShowError(KeyName, true, "身份证号不能为空");
        return false;
    }
    var reg = /^\d{15}$|^\d{17}(?:\d|x|X)$/;
    if (!reg.test(idCard)) {
        ShowError(KeyName, true, "请填写正确的身份证号");
        return false;
    }
    ShowRight(KeyName, true, '身份证已输入');
    return true;
}

function CheckMobile2(KeyName, Status, CityName, Mobile, AreaCode, OldPhone) {
    //用于手机号码前三位编码验证
    var Prefix_Mobile = new Array(130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189);
    //CityName没值时不校验数据库
    if (CityName == '' || CityName == '请选择')
        Status = 2; //不处理
    if (Mobile == '') {
        ShowError(KeyName, true, "移动电话不能为空");
        return false;
    }
    else {
        var regcode = /^\d{11,11}$/;
        if (!regcode.test(Mobile) && Status != 3) {
            ShowError(KeyName, true, "请输入正确的移动电话,应输入11位的数字编号");
            return false;
        }
        else if (Status == 3) {
            regcode = /^\d{7,8}$/;
            if (!regcode.test(Mobile)) {
                ShowError(KeyName, true, "请输入正确的移动电话,应输入7位或8位的数字编号");
                return false;
            }
            if (AreaCode == "") {
                ShowError(KeyName, true, "小灵通区号不能为空");
                return false;
            }
        }
        //手机验证
        if (Status == 0 || Status == 1) {
            //取当前输入手机号码的前三位（以便与预定的手机前三位号码做验证）
            var PreMobile = Mobile.substring(0, 3)
            for (var i = 0; i < Prefix_Mobile.length; i++) {
                if (PreMobile == Prefix_Mobile[i]) {
                    checkphone = true;
                    break;
                }
                if (i == Prefix_Mobile.length - 1) {
                    ShowError(KeyName, true, "手机号码前三位不正确");
                    return false;
                }
            }
        }
        if (Status == 1 && Mobile != OldPhone) {
            ShowError(KeyName, true, "正在检索。。。");
            url = '/AjaxPage/RegisterHelper.aspx?action=checkmobile&mobile=' + Mobile + '&status=' + Status + '&cityname=' + escape(CityName) + '&run=' + Math.random();
            Ajax.Request(url, ProcessResult, AjaxError, null, 'text', null, '');
        }
        else if (Status == 0) {
            ShowError(KeyName, true, "正在检索。。。");
            url = '/AjaxPage/RegisterHelper.aspx?action=checkmobile&mobile=' + Mobile + '&status=' + Status + '&cityname=' + escape(CityName) + '&run=' + Math.random();
            Ajax.Request(url, ProcessResult, AjaxError, null, 'text', null, '');
        }
        //小灵通
        else if (Status == 3) {
            ShowError(KeyName, true, "正在检索。。。");
            url = '/AjaxPage/RegisterHelper.aspx?action=checkmobile&mobile=' + AreaCode + Mobile + '&status=0&cityname=' + escape(CityName) + '&run=' + Math.random();
            Ajax.Request(url, ProcessResult, AjaxError, null, 'text', null, '');
        }
        else {
            ShowTip(KeyName, true);
            checkphone = true;
        }
    }
    return checkphone;
}

function ProcessResult() {
    var result = this.req.responseText;
    if (result == "false") {
        checkphone = true;
        ShowRight("txtMobile", true);
    } else {
        checkphone = false;
        var name = result.substr(4);
        ShowError("txtMobile", true, '该手机号已经被用户名为<span style="color:blue;">' + name + '</span>使用，如您忘记了密码，请使用<a href="http://passport.soufun.com/get_password.aspx" style="color:blue;" target="_blannk">找回密码</a>功能，我们会将您之前的密码发送至您之前注册的安全邮箱中。如您认为是恶意抢注，请与当地客服联系。');
    }
}
function CheckPhone(Phone1, Phone2, Phone3, KeyName) {
    if (oo(Phone1).readOnly == true) {
        ShowTip(KeyName, true);
        return true;
    }
    var phone1 = trim(oo(Phone1).value);
    var phone2 = trim(oo(Phone2).value);
    var phone3 = trim(oo(Phone3).value);
    if (phone1 + phone2 + phone3 != '') {
        var regcode = /^\d{3,4}$/;
        var regphone = /^[1-9]\d{6,7}$/;
        if (phone1 != "" && !regcode.test(phone1)) {
            ShowError(KeyName, true, "区号只能为3-4位数字");
            return false;
        }
        if (!regphone.test(phone2)) {
            ShowError(KeyName, true, "座机号不能为空，并且只能为7-8位数字");
            return false;
        }
        if (phone3 != "" && !regcode.test(phone3)) {
            ShowError(KeyName, true, "分机号只能为3-4位数字");
            return false;
        }
        ShowRight(KeyName, true);
        return true;
    } else {
        ShowTip(KeyName, true);
        return true;
    }
}
function CheckInviter(KeyName, UserName) {
    if (oo(KeyName).readOnly == true) {
        ShowTip(KeyName, true);
        return true;
    } else {
        var inviter = trim(oo(KeyName).value);
        var username = oo(UserName).value;
        if (inviter != "") {
            if (LenObject(inviter) > 30) {
                ShowError(KeyName, true, '邀请人用户名太长');
                return false;
            }
            if (inviter == username) {
                ShowError(KeyName, true, '不能与您的用户名相同');
                return false;
            }
            ShowRight(KeyName, true);
            return true;
        } else {
            ShowTip(KeyName, true);
            return true;
        }
    }
}
function CheckCode(KeyName) {
    var code = $$(KeyName).value;
    var regcode = /^\d{4}$/;
    if (code == "") {
        ShowError(KeyName, true, "不能为空");
        return false;
    } else if (!regcode.test(code)) {
        ShowError(KeyName, true, "验证码只能为4位数字");
        return false;
    } else {
        ShowRight(KeyName, true);
        return true;
    }
}
function ShowDiv(i) {
    for (var j = 1; j <= 4; j++) {
        $$('Div' + j).style.display = 'none';
    }
    $$('Div' + i).style.display = 'block';
}
function CheckLength(KeyName, Size) {
    if (oo(KeyName).readOnly == true) {
        ShowTip(KeyName, true);
        return true;
    }
    var value = trim(oo(KeyName).value);
    if (value != "") {
        if (LenObject(value) > Size) {
            ShowError(KeyName, true, '输入太长');
            return false;
        }
        ShowRight(KeyName, true);
        return true;
    } else {
        ShowTip(KeyName, true);
        return true;
    }
}
function CheckMSN(KeyName) {
    var value = $$(KeyName).value;
    if (value != "") {
        if (value.length > 40) {
            ShowError(KeyName, true, "输入太长");
            return false;
        }
        var regEmail = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(value);
        if (!regEmail) {
            ShowError(KeyName, true, "MSN格式不正确");
            return false;
        }
        ShowRight(KeyName, true);
        return true;
    } else {
        ShowTip(KeyName, true);
        return true;
    }
}
function CheckQQ(KeyName) {
    var qq = $$(KeyName).value;
    if (qq != "") {
        var regqq = /^[1-9]\d{5,12}$/;
        if (qq != "0" && !regqq.test(qq)) {
            ShowError(KeyName, true, "QQ号码格式不正确！");
            return false;
        }
        ShowRight(KeyName, true);
        return true;
    } else {
        ShowTip(KeyName, true);
        return true;
    }
}
function CheckBlog(KeyName) {
    var blogurl = $$(KeyName).value;
    if (blogurl != "") {
        if (LenObject(blogurl) > 100) {
            ShowError(KeyName, true, '输入过长');
            return false;
        }
        var regblog = /^http:\/\/blog.soufun.com\/blog_\d{6,}.htm$/;
        if (!regblog.test(blogurl)) {
            ShowError(KeyName, true, "您输入的博客地址不是有效的搜房博客地址！");
            return false;
        }
        ShowRight(KeyName, true);
        return true;
    } else {
        ShowTip(KeyName, true);
        return true;
    }
}

function CheckSubmit() {
    if (!checknameandphone)
        return false;

    var b = CheckPwd('txtUserPwd', 'txtUserName');
    var c = CheckPwdAgain('txtUserPwdAgain', 'txtUserPwd');
    var d = CheckEmail('txtUserEmail');
    var e = CheckSelect1('txtCity', 2);
    var f = CheckSelect1('txtDistrict', 3);
    var g = CheckSelect1('selComareas', 4);
    //var g = CheckCode('txtCode');
    var h = CheckName('txtRealName');
    var i = true;
    //var i = CheckIDCard('txtIDCard');
    var j = CheckPhone('txtPhone1', 'txtPhone2', 'txtPhone3', 'txtPhone');

    var cityName = $$('txtCity').options[$$('txtCity').selectedIndex].value;
    var mobile1 = $$('txtMobile').value;
    var mobile2 = $$('txtMobile2').value;
    var code = $$('AreaCode').value;
    var contactMode = $$('ContactMode').value;

    if (!checkname) {
        CheckUserName('txtUserName');
        return false;
    }
    if (!checkphone) {
        if (contactMode == 1)
            CheckMobile2('txtMobile', 0, cityName, mobile1);
        else
            CheckMobile2('txtMobile', 3, cityName, mobile2, code);
        return false;
    }
    //var l = CheckInviter('txtInviter','txtUserName');

    var l = CheckCompany("txtCompany");

    if (b && c && d && e && f && g && h && i && j && l) {
        return true;
    } else {
        alert("请根据提示进行正确输入");
        return false;
    }
}
//Ajax请求失败时执行
function AjaxError() 
{
    alert("数据传输错误，或网络故障，请重试");
    window.location.reload();
}

//#Region控制页面显示
function ShowTip(KeyName, flag) {
    var tipName = "#" + KeyName + "_tip";
    if (flag) {
        $(tipName).css("display", "");
        ShowError(KeyName, false);
        ShowRight(KeyName, false);
    } else {
        $(tipName).css("display", "none");
    }
}
function ShowError(KeyName, flag, msg) {
    var ErrorName = "#" + KeyName + "_error";
    if (flag) {
        $(ErrorName).css("display", "");
        $(ErrorName).html("<img src='/Images/register/reg_07.gif'/>&nbsp;" + msg);
        ShowTip(KeyName, false);
        ShowRight(KeyName, false);
        ChangeDivClass(KeyName, 'onwred');
    } else {
        $(ErrorName).css("display", "none");
        ChangeDivClass(KeyName, '');
    }
}
function ShowRight(KeyName, flag, msg) {
    var RightName = "#" + KeyName + "_right";
    if ((KeyName == "txtMobile" || KeyName == "txtUserName") && flag)
        checknameandphone = true;
    else if ((KeyName == "txtMobile" || KeyName == "txtUserName") && !flag)
        checknameandphone = false;
    if (flag) {
        $(RightName).css("display", "");
        if (msg != null) {
            $(RightName).html("<img src='/Images/register/reg_08.gif'/>&nbsp;" + '<label class="ok">' + msg + '</label>');
        } else {
            $(RightName).html("<img src='/Images/register/reg_08.gif'/>&nbsp;" + '<label class="ok">' + '已输入' + '</label>');
        }
        ShowTip(KeyName, false);
        ShowError(KeyName, false);
    } else {
        $(RightName).css("display", "none");
    }
}
function ChangeDivClass(KeyName, classN) {
    var divName = "#" + KeyName + "Div";
    if (KeyName == "txtDistrict" || KeyName == "selComareas")
        divName = "#" + "txtCityDiv";
    $(divName).attr("class", classN);
}
//#endRegion控制页面显示

//#region 公共函数
//计算字符串长度
function LenObject(key) {
    var l = escape(key);
    var len = l.length - (l.length - l.replace(/\%u/g, "u").length) * 4;
    l = l.replace(/\%u/g, "uu");
    len = len - (l.length - l.replace(/\%/g, "").length) * 2;
    return len;
}
//判断是否是包含汉字
function isChina(s) {
    var regu = "^[\u4e00-\u9fa5]+$";
    var re = new RegExp(regu);
    var arstr = new Array();
    arstr = toCharArray(s);
    for (var i = 0; i < arstr.length; i++) {
        if (re.test(arstr[i])) {
            return true;
            break;
        }
        else {
            continue;
        }
    }
    return false;
}
//将字符串转换成字符数组
function toCharArray(str) {
    var charArr = new Array();
    for (var i = 0; i < str.length; i++) charArr[i] = str.charAt(i);
    return charArr;
}
//#endRegion 公共函数


//js扩展  
String.prototype.endWith = function(str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.startWith = function(str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
}